package com.zonta.finance.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.zonta.finance.common.dto.ApiResponse;
import com.zonta.finance.common.dto.PageInfo;
import com.zonta.finance.domain.form.*;
import com.zonta.finance.domain.po.AccountBook;
import com.zonta.finance.domain.vo.GetAccountBookVo;
import com.zonta.finance.domain.vo.ListAccountBookVo;
import com.zonta.finance.serivce.IAccountBookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Api(tags = "账套")
@RestController
@RequestMapping(value = "/account_book")
@RequiredArgsConstructor
@Slf4j
@Validated
public class AccountBookController {
    final IAccountBookService accountBookService;
    @ApiOperation(value = "获取账套详情")
    @GetMapping(value = "/get")
    public ApiResponse<GetAccountBookVo> get(@NotNull @Min(value = 1) @RequestParam long id) {
        GetAccountBookVo getAccountBookVo = accountBookService.getByIdVo(id);
        return ApiResponse.success(getAccountBookVo);
    }

    @ApiOperation(value = "查询账套列表")
    @GetMapping(value = "/list")
    public ApiResponse<PageInfo<ListAccountBookVo>> list(@Validated @ModelAttribute ListAccountBookForm form) {
        return ApiResponse.success(accountBookService.getListByFrom(form));
    }

    @ApiOperation(value = "创建账套")
    @PostMapping(value = "/add")
    public ApiResponse<Boolean> add(@Validated @RequestBody AddAccountBookForm form) {

        return ApiResponse.success(accountBookService.saveByFrom(form));
    }

    @ApiOperation(value = "禁用启用账套")
    @PostMapping(value = "/disable")
    public ApiResponse<Boolean> disable(@Validated @RequestBody AccountBookDisableForm form) {
        return ApiResponse.success(accountBookService.disable(form));
    }

    @ApiOperation(value = "删除账套")
    @PostMapping(value = "/del")
    public ApiResponse<Boolean> del(@Valid @RequestBody DelForm form) {
        return ApiResponse.success(accountBookService.del(form));
    }

    @ApiOperation(value = "编辑账套")
    @PostMapping(value = "/update")
    public ApiResponse<Boolean> update(@Validated @RequestBody UpdateAccountBookForm form) {
        return ApiResponse.success(accountBookService.updateByFrom(form));
    }
}
